﻿@model Lehnet.Models.Musteri
@{Html.RenderPartial("FancyRequireScripts");}
<script>

    $(document).ready(function () {
        getallMusteriAjax();

        $(".various").fancybox({
            maxWidth: 800,
            maxHeight: 600,
            fitToView: false,
            width: '70%',
            height: '70%',
            autoSize: false,
            closeClick: true,
            openEffect: 'elastic',
            closeEffect: 'fade',
            modal: true
        });
    });
    function confirmDelete(musteriId) {
        if (confirm("Silinecek Kayıtlar: müşteri, müşteri personeli, kayıtlı adresleri.\nBu kaydı silmek istediğinize emin misiniz?") == false)
            return;
        DeleteMusteriAjax(musteriId);
    }
    function DeleteMusteriAjax(musteriId) {
        $.ajax({
            url: '/Musteri/DeleteMusteriAjax',
            data: {
                musteriId: musteriId
            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                getallMusteriAjax();
            }
        });
    }
    function getallMusteriAjax() {

        $("#createLink").attr('href', '/Musteri/Create');
        $.ajax({
            url: '/Musteri/GetAllMusterilerAjax',
            data: {

            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                var JSONData = eval(data);
                $("#tblMusteriler").children().remove();
                $('#tblMusteriler').append(
                     '<thead> <tr>' +
                        '<th>Ad</th>' +
                        '<th>Ünvan</th>' +
                        '<th>Web</th>' +
                        '<th>EMail1</th>' +
                        '<th>VergiDairesi</th>' +
                        '<th>VergiNo</th>' +
                        '<th>Personeller</th>' +
                        '<th>Adresleri</th>' +
                        '<th>Düzenle</th>' +
                        '<th>Sil</th>' +
                    ' </tr></thead>');
                $.each(JSONData, function (index, itemData) {

                    $('#tblMusteriler').append(
                        '<tr>' +
                            '<td>' + itemData.Ad + '</td>' +
                            '<td>' + itemData.Unvan + ' </td>' +
                            '<td>' + itemData.Web + ' </td>' +
                            '<td>' + itemData.EMail1 + ' </td>' +
                            '<td>' + itemData.VergiDairesi + ' </td>' +
                            '<td>' + itemData.VergiNo + ' </td>' +
                            '<td><a href="/MusteriPersoneli/Index/' + itemData.Id.toString() + '" class="various" data-fancybox-type="iframe">Listele</a></td>' +
                            '<td><a href="/MusteriAdresi/Index/' + itemData.Id.toString() + '" class="various" data-fancybox-type="iframe">Listele</a></td>' +
                            '<td><a href="/Musteri/Create/' + itemData.Id.toString() + '" class="various" data-fancybox-type="iframe">Düzenle</a></td>' +
                            '<td><a href="#" onclick="confirmDelete(' + itemData.Id.toString() + ')" >Sil</a></td>' +
                        '</tr>');
                });
            }
        });
    }

</script>
<p>
</p>
<a id="createLink" href='#' class='various' data-fancybox-type='iframe'>
    <img width="18" height="18" src="/Content/IconImages/plus.png" /></a>
<table id="tblMusteriler" class="bordered" width="100%">
</table>
